import requests,json
#code='0.399004' #深圳100
#code='0.399006' #创业板
#code='0.399967' #军工
#code='0.399417' #新能源车
#code='90.BK0473' #券商
#code='90.BK0475' #银行
#code='1.000016' #上证50
#code='1.000300' #上证50
#code='1.000905' #中证500
#code='0.399989' #中证医疗
#code='1.000827' #中证环保
codes=['0.399006','0.399417','90.BK0473','1.000016','1.000300','1.000905','0.399989','1.000827']
num_days=120

dict_funds={}

for code in codes:

    url = 'http://push2his.eastmoney.com/api/qt/stock/kline/get?cb=jQuery112405635482645650303_1608307414376&secid={}&ut=fa5fd1943c7b386f172d\
    6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58&klt=101&fqt=0&beg=20200101&end=20220101&_=1608307414377'.format(code)
        #print(url)
        #print(code)
    req = requests.get(url)
    y=req.text
    x=req.text[42:-2]
    z=0

        #print(x)
    dict_funds[code]=json.loads(x,strict=False)

for code in dict_funds.keys():
    vols=[]
    for i in range(-1,-11,-1):
        #print(i)
        vols.append(float(dict_funds[code]['data']['klines'][i].split(',')[6]))
    vols.sort(reverse=True)
        
    print('日期:',dict_funds[code]['data']['klines'][-1].split(',')[0],code,dict_funds[code]['data']['name'],\
          '指数涨跌幅:',"{:.2%}".format(float(dict_funds[code]['data']['klines'][-1].split(',')[2])/float(dict_funds[code]['data']['klines'][-2].split(',')[2])-1),\
          '成交量10日内排名',vols.index(float(dict_funds[code]['data']['klines'][-1].split(',')[6]))+1,\
          '成交量与昨日对比:',"{:.2%}".format(float(dict_funds[code]['data']['klines'][-1].split(',')[6])/float(dict_funds[code]['data']['klines'][-2].split(',')[6])-1),\
           '实际成交金额:',dict_funds[code]['data']['klines'][-1].split(',')[6]
          )
        
    
